#ifndef WCOLLISIONSOLVER
#define WCOLLISIONSOLVER

#include <SFML\Graphics.hpp>
#include "WorldElement.h"
#include "Actor.h"

enum TILETYPE{TT_empty,TT_solid,TT_plat,TT_hurt,TT_shadow};



class CollisionSolver
{
	TILETYPE **m_grid;
	int m_width,m_height;
	int m_twidth,m_theight;
	sf::Sprite **m_sprites;
	int m_numsprites;

	std::vector <Actor*> *p_actors;

	sf::Vector2f getTileCenter(int x, int y);

	bool TileEdge(int x, int y, int side);

	int getSide(sf::Vector2f direction);

	float DotProjection(sf::Vector2f vector, sf::Vector2f onto);

	TILETYPE getTileType(int x, int y);



public:

	CollisionSolver(TILETYPE **grid, int width, int height, int twidth, int theight);

	~CollisionSolver();

	bool getCollision(sf::Vector2f *position, sf::Vector2f *velocity,float dt, sf::Vector2f size);

	bool getPlatCollision(sf::Vector2f *position, sf::Vector2f *velocity, sf::Vector2f size, sf::Rect <int> rect,float dt);

	TILETYPE getTileType(sf::Vector2f pos);

	WorldElement *getElement(sf::Vector2f pos);

	void setSprites(sf::Sprite **sprites, int numsprites);

	int getNumsprites();
	sf::Sprite **getSprites();

	void Update(float dt);

	void Link(std::vector <Actor*> *actors);

	std::vector<Actor*> *getActorvector();

	Actor *getActorCollision(Actor *me, sf::Vector2f *velocity, float dt);

	Actor *getActorCollision(Actor *me, sf::Rect <int> rectangle, ACTORTYPE at);
};

#endif